//
//  ViewController.m
//  adaptive
//
//  Created by xingshuai on 2021/2/20.
//

#import "ViewController.h"

#import <Masonry.h>
#import "TableViewCell.h"

@interface ViewController () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *table;
@property (nonatomic, strong) NSArray *arrList;

@end

@implementation ViewController

-(NSArray *)arrList {
    if (!_arrList) {
        _arrList = @[@"华士大夫那地方第三方你们大梅",@"富家大室那顿饭， 迪士尼发送到封面，ad赛诺菲啊，模式DNF阿萨德拿饭吗阿萨德，发阿斯顿发",@"阿斯顿发答复阿斯顿发生大声道发送到范德萨发阿道夫发多少发的发电房阿凡达挨打发送安抚阿斯顿发阿斯顿发阿斯顿发阿斯顿发答复阿斯顿发生大声道发送到范德萨发阿道夫发多少发的发电房阿凡达挨打发送安抚阿斯顿发阿斯顿发阿斯顿发",@"阿萨德发送到发斯蒂芬阿斯顿发啊啊士大夫阿斯顿发个阿萨德",@"大阿萨德啊"];
    }
    return _arrList;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = UIColor.orangeColor;
    
    [self creatViewUI];
}

-(void)creatViewUI {
    [self.view addSubview:self.table];
    [self.table mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view).offset(44);
        make.bottom.equalTo(self.view).offset(-34);
    }];
}

-(UITableView *)table {
    if (!_table) {
        _table = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _table.delegate = self;
        _table.dataSource = self;
        _table.tableFooterView = [UIView new];
        //_table.estimatedRowHeight = 100;
        //_table.rowHeight = UITableViewAutomaticDimension;
        
        if (@available(iOS 11.0,*)) {
            _table.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        } else {
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
    }
    return _table;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.arrList.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellid = @"cellid";
    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
    if (!cell) {
        cell = [[TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
    }
    
    if (self.arrList.count > indexPath.row) {
        cell.str = [self.arrList objectAtIndex:indexPath.row];
    }
    return cell;
}


@end
